module sdldee.video.pixelformat;

import sdldee.c.sdl;
import sdldee.video.palette;
import sdldee.video.colour;

class PixelFormat {
	private SDL_PixelFormat* _format;
	
	this(SDL_PixelFormat* format) {
		_format = format;
	}
	
	public SDL_PixelFormat* cformat() {
		return _format;
	}
	
	public Palette palette() {
		return new Palette(_format.palette);
	}
	
	public ubyte bitsPerPixel() {
		return _format.BitsPerPixel;
	}
	
	public ubyte bytesPerPixel() {
		return _format.BytesPerPixel;
	}
	
	public ubyte rLoss() {
		return _format.Rloss;
	}
	
	public ubyte gLoss() {
		return _format.Gloss;
	}
	
	public ubyte bLoss() {
		return _format.Bloss;
	}
	
	public ubyte aLoss() {
		return _format.Aloss;
	}
	
	public ubyte rShift() {
		return _format.Rshift;
	}

	public ubyte gShift() {
		return _format.Gshift;
	}

	public ubyte bShift() {
		return _format.Bshift;
	}
	
	public ubyte aShift() {
		return _format.Ashift;
	}
	
	public uint rMask() {
		return _format.Rmask;
	}
	
	public uint gMask() {
		return _format.Gmask;
	}
	
	public uint bMask() {
		return _format.Bmask;
	}

	public uint aMask() {
		return _format.Amask;
	}
	
	public uint colourKey() {
		return _format.colorkey;
	}
	
	public ubyte alpha() {
		return _format.alpha;
	}
	
	public uint mapColour(Colour colour) {
		return SDL_MapRGB(cformat, colour.r, colour.g, colour.b);
	}
	
	public uint mapColour(Colour colour, ubyte alpha) {
		return SDL_MapRGBA(cformat, colour.r, colour.g, colour.b, alpha);
	}
	
	public Colour getColour(uint pixel) {
		ubyte r, g, b;
		SDL_GetRGB(pixel, cformat, &r, &g, &b);
		return new Colour(r, g, b);
	}
	
	public Colour getColour(uint pixel, out ubyte alpha) {
		ubyte r, g, b;
		SDL_GetRGBA(pixel, cformat, &r, &g, &b, &alpha);
		return new Colour(r, g, b);
	}
}
